package com.ngc.mall.controller;

import com.ngc.mall.common.configure.response.ResponseResult;
import com.ngc.mall.domain.FreightTemplateDomain;
import com.ngc.mall.service.IFreightTemplateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 物流控制类
 * @author: chenxiaolin
 * @date 2023/11/6 13:47
**/
@RestController
@RequestMapping("/logistics")
public class LogisticsController {

    @Autowired
    private IFreightTemplateService iFreightTemplateService;

    @GetMapping("/freight-template/list")
    @ApiOperation("获取所有运费模板")
    public ResponseResult<List<FreightTemplateDomain>> queryAllFreightTemplate(){
        return ResponseResult.success(iFreightTemplateService.queryAll());
    }

    @PostMapping("/freight-template")
    @ApiOperation("新增运费模板")
    public ResponseResult<Long> createFreightTemplate(@RequestBody FreightTemplateDomain domain){
        return ResponseResult.success(iFreightTemplateService.createFreightTemplate(domain));
    }

    @PutMapping("/freight-template/id/{id}")
    @ApiOperation("根据id更新运费模板")
    public ResponseResult<Boolean> updateFreightTemplateById(@PathVariable Long id,@RequestBody FreightTemplateDomain domain){
        return ResponseResult.auto(iFreightTemplateService.updateById(id,domain));
    }

    @DeleteMapping("/freight-template/id/{id}")
    @ApiOperation("根据id删除运费模板")
    public ResponseResult<Boolean> deleteFreightTemplateById(@PathVariable Long id){
        return ResponseResult.auto(iFreightTemplateService.deleteById(id));
    }
}
